package com.example.it.fragments;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.it.R;
import com.example.it.View.ItView;
import com.example.it.adapter.ItInAdapter;
import com.example.it.base.BaseFragment;
import com.example.it.bean.ItInfoItemBean;
import com.example.it.presenter.ItPrsenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class ItInFragment extends BaseFragment<ItPrsenter> implements ItView {
    private  int page=1;
    private String name;
    @BindView(R.id.recyler)
    RecyclerView mrecyler;
    private ArrayList<ItInfoItemBean.DataBean.DatasBean> datasBeans;
    private ItInAdapter itInAdapter;
    public void  getInstance(String tabTitle,int id){
       /* ItInFragment fragment = new ItInFragment();
        Bundle bundle = new Bundle();
        bundle.putString("name",tabTitle);
        bundle.putInt("id",id);
        fragment.setArguments(bundle);*/
    }
    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        Bundle arguments = getArguments();
        int id = arguments.getInt("id");
        mPresenter.getdata(id,page);
        mrecyler.setLayoutManager(new LinearLayoutManager(getContext()));
        mrecyler.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        datasBeans = new ArrayList<>();
        itInAdapter = new ItInAdapter(getContext(), datasBeans);
        mrecyler.setAdapter(itInAdapter);
    }

    @Override
    protected void initPrsesnter() {
        mPresenter=new ItPrsenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_it_in;
    }



    @Override
    public void onSuccess(ItInfoItemBean data) {
        List<ItInfoItemBean.DataBean.DatasBean> datas = data.getData().getDatas();
        datasBeans.clear();
        datasBeans.addAll(datas);
        itInAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
